# 邮件通知工具
import smtplib
from email.mime.text import MIMEText
from tests.utils.log_utils import LogUtils
logger = LogUtils().get_logger()


class EmailUtils:
    def __init__(self):
        self.smtp_server = "smtp.example.com"
        self.smtp_port = 587
        self.sender = "sender@example.com"
        self.password = "password"

    def send_email(self, message):
        """发送邮件通知"""
        receiver = "receiver@example.com"
        msg = MIMEText(message, "plain", "utf-8")
        msg["From"] = self.sender
        msg["To"] = receiver
        msg["Subject"] = "接口自动化测试结果"

        with smtplib.SMTP(self.smtp_server, self.smtp_port) as server:
            server.starttls()
            server.login(self.sender, self.password)
            server.sendmail(self.sender, receiver, msg.as_string())
        logger.info("邮件通知发送完成")
